import type {IColumnsOption} from 'vc';
import {
  INDEX,
  COMPANY_NAME,
  BUSINESS_DATA,
  REGISTERED_CAPITAL,
  PROVINCE,
  CITY,
  COUNTRY,
  INDUSTRY_CATEGORY
} from '@/utils/tableColumn';
import {toF9} from '@/utils';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    {...INDEX},
    {
      field: 'evaluationAgency',
      title: '评估机构',
      width: 300,
      fixed: 'left',
      headerAlign: 'center',
      sortBy: 'evaluationAgency',
      slots: {
        default: ({row}) => {
          const content = row.highlight?.evaluationAgency ? row.highlight?.evaluationAgency : row.evaluationAgency;
          if (row.companyId) {
            return <a title={row.evaluationAgency} class="companyName"
                      onClick={() => toF9(row.companyId)}
                      v-html={content}></a>;
          } else {
            return <span title={row.evaluationAgency || ''} v-html={content || '-'}></span>;
          }
        }
      }
    },

    {
      field: 'stockCount',
      title: '认证绿色债券数',
      align: 'center',
      width: 200,
      slots: {
        default: ({row}) => {
          if (row.stockCount) {
            return (
              <div>
                <a onClick={() => BondEvaluateDetailFn(row, 'bond')}>{row.stockCount}只</a>
                <br/>
              </div>)

          } else {
            return (<span>-</span>)
          }
        }
      }
    },
    {
      field: 'bodyCount',
      title: '认证绿色企业数',
      align: 'center',
      width: 200,
      slots: {
        default: ({row}) => {
          if (row.bodyCount) {
            return (
              <div>
                <a onClick={() => BondEvaluateDetailFn(row, 'issue')}>{row.bodyCount}家</a>
                <br/>
              </div>)

          } else {
            return (<span>-</span>)
          }
        }
      }
    },
    {...PROVINCE, sortable: false},
    {...CITY, sortable: false},
    {...COUNTRY, sortable: false},
    {...INDUSTRY_CATEGORY, sortable: false},
    {...BUSINESS_DATA, sortable: false},
    {...REGISTERED_CAPITAL, sortable: false}
  ]);

  // 评估机构详情弹窗
  const showBondEvaluateDetail = ref(false);
  const BondEvaluateDetails = ref([]);
  const BondEvaluateShowIndex = ref();

  const BondEvaluateDetailFn = (data, code) => {
    showBondEvaluateDetail.value = true;
    BondEvaluateShowIndex.value = code;
    BondEvaluateDetails.value = data;
  };

  return {
    columns,
    showBondEvaluateDetail,
    BondEvaluateDetails,
    BondEvaluateShowIndex

  };
}
